<?php
	//Funktion som skapar ett slumpat lösenord och hashar det. Båda skickas sedan tillbaka i en array.
	function CreatePassword()
	{
		$password=random_string('alnum',8);
		$hashPassword=dohash($password);
		
		return array('password'=>$password,'hashPassword'=>$hashPassword);
	}
	
	
	function CreateOCR($personNummer)
	{
		
		//30 dagar i sekunder
		$span=2592000;
				
		$nowDate=mktime();
		$bokTid=date('ydmHi',$nowDate);
		$bokTidReturn=date('Y-m-d G:i:s',$nowDate);
		
		$forFalloDag=$nowDate+$span;
		
		$forFalloDag=date('Y-m-d',$forFalloDag);
		$number=$personNummer.$bokTid;
		
		
		$stack = 0;
		$number = str_split(strrev($number));
		
		foreach ($number as $key => $value)
		{
		    if ($key % 2 == 0)
		    {
		        $value = array_sum(str_split($value * 2));
		    }
		    $stack += $value;
		}
		$stack %= 10;
		
		if ($stack != 0)
		{
		    $stack -= 10;     $stack = abs($stack);
		}
		
		
		$number = implode('', array_reverse($number));
		$number = $number . strval($stack);
		
		
		$ocrInfo=array('ocrNummer'=>$number,'tid'=>$bokTidReturn,'forFallo'=>$forFalloDag);
		return $ocrInfo;
	}
	
	
	
?>